<template>
  <div id="ReceiptPreflightDetails">
    <v-detail :detailData="inputData"
              :inputConfig="inputConfig"
              :rules="rules"
              @pop="setData"
              ref="input"></v-detail>
  </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "ReceiptPreflightDetails",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object
    }
  },
  data () {

    return {
      inputConfig: [
        [
          {
            type: "input",
            label: this.$t('in.receiptpreflightkey'),
            props: "receiptpreflightkey",
            disabled: true
          },
          {
            type: "input",
            label: this.$t('in.importkey'),
            props: "importkey",
            disabled: !this.$parent.newFlag
          },
          {
            type: "input",
            label: this.$t('in.excelgroupkey'),
            props: "excelgroupkey"
          },
          {
            type: "input",
            label: "ASN",
            props: "receiptkey",
            disabled: true
          },
          {
            type: "select",
            label: this.$t('in.receipttype'),
            props: "receipttype",
            options: this.getOptions("codelkup/RECEIPTYPE")
          },
          {
            type: "input",
            label: this.$t('config.supplier'),
            props: "vendor",
          },
        ],
        [
          {
            type: "input",
            label: this.$t('config.shipper'),
            props: "storerkey",
            disabled: true
          },
          {
            type: "table",
            label: this.$t('config.sku'),
            disabled: false,
            props: "sku",
            tableConfig: [
              {
                label: this.$t('config.sku'),
                prop: "sku",
                input: "input"
              },
              {label: this.$t('common.desc'), prop: "descr", input: "input"},
              {
                label: this.$t('config.shipper'),
                prop: "storerkey",
                input: "input"
              },
              {label: this.$t('config.packaging'), prop: "packkey", input: "input"},
              {
                label: this.$t('config.boxGroup'),
                prop: "cartongroup",
                input: "select",
                options: this.getOptions("queryCartonizationDropDown")
              },
              {
                label: this.$t('config.allocaStrategy'),
                prop: "strategykey",
                input: "select",
                options: this.getOptions("queryAllocatestrategyDropDown")
              },
              {
                label: this.$t('config.putawayStrategy'),
                prop: "putawaystrategykey",
                input: "select",
                disabled: false,
                options: this.getOptions("queryPutawaystrategyDropDown")
              },
              {
                label: this.$t('config.batchValidate'),
                prop: "lottablevalidationkey",
                input: "select",
                options: this.getOptions("queryLottablevalidationDropDown")
              },
              {
                label: this.$t('config.area'),
                prop: "putawayzone",
                input: "select",
                options: this.getOptions("queryPutawayzoneDropDown")
              }
            ],
            url: `querySku/?/${this.$store.state.wms}/`
            // url: 'querySkuOfStorerkey/?/wmwhse1/undefined'
          },
          {
            type: "date",
            label: this.$t('in.generatedate'),
            props: "generatedate",
          },
          {
            type: "input",
            label: this.$t('in.vendorbatch'),
            props: "vendorbatch"
          },
          {
            type: "input",
            label: this.$t('in.origin'),
            props: "origin",
          },
          {
            type: "input",
            label: this.$t('in.legalkey'),
            props: "legalkey",
          }
        ],
        [
          {
            type: "select",
            label: this.$t('in.potype'),
            props: "potype",
            options: this.getOptions("codelkup/JDEPOTYPE")
          },
          {
            type: "input",
            label: this.$t('in.pono'),
            props: "pono",
          },
          {
            type: "input",
            label: this.$t('in.arrivalqty'),
            props: "arrivalqty"
          },
          {
            type: "select",
            label: this.$t('outbound.uom'),
            props: "uom",
            options: this.getOptions("codelkup/defaultUom/STD")
          },
          {
            type: "date",
            label: this.$t('in.lastdate'),
            props: "lastdate",
            disabled: true
          },
          {
            type: "input",
            label: this.$t('in.specialresult'),
            props: "specialresult",
            disabled: true
          }
        ],
        [
          {
            type: "input",
            label: this.$t('in.skuneed'),
            props: "skuneed",
            disabled: true
          },
          {
            type: "date",
            label: this.$t('app.expecteddate'),
            props: "expecteddate"
          },
          {
            type: "input",
            label: this.$t('in.lottable08'),
            props: "lottable08",
            disabled: true
          },
          {
            type: "input",
            label: this.$t('in.externpokey'),
            props: "externpokey",
            disabled: true
          },
          {
            type: "input",
            label: this.$t('in.quarantine'),
            props: "quarantine",
          },
          {
            type: "input",
            label: this.$t('in.liquorticket'),
            props: "liquorticket",
          }
        ]
      ],
      rules: {
        receiptpreflightkey: [
          { required: true,  trigger: 'blur' },
        ],
        excelgroupkey: [
          { required: true,  trigger: 'blur' },
        ],
        receipttype: [
          { required: true,  trigger: 'blur' },
        ],
        vendor: [
          { required: true,  trigger: 'blur' },
        ],
        legalkey: [
          { required: true,  trigger: 'blur' },
        ],
        storerkey: [
          { required: true,  trigger: 'blur' },
        ],
        sku: [
          { required: true,  trigger: 'blur' },
        ],
        potype: [
          { required: true,  trigger: 'blur' },
        ],
        pono: [
          { required: true,  trigger: 'blur' },
        ],
        generatedate: [
          { required: true,  trigger: 'blur' },
        ],
        arrivalqty: [
          { required: true,validator: this.arrivalqty,  trigger: 'blur' },
        ],
        uom: [
          { required: true,  trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
    arrivalqty(rule, value, callback) {
      if (value === '') {
        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
        this.inputData[rule.field] = "";
        callback(new Error());
      } else {
        var re = /^[1-9]+[0-9]*$/;
        let te = value;
        let flag = re.test(te);
        if (flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
            this.inputData[rule.field] = "";
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
          this.inputData[rule.field] = "";
          callback(new Error());
        }
      }
    },
    setData (data, id, callback) {
      if (id == "1") {
        this.inputData.storerkey = data.storerkey;
        this.inputData.sku = data.sku;
      }
      callback(false);
    }
  },
  mounted () {

  },
  components: {
    "v-detail": detail
  }
}
</script>

<style scoped>
</style>
